package com.aisino.inveli.vinda.controller;

import com.aisino.inveli.vinda.entity.Customer;
import com.aisino.inveli.vinda.service.CustomerService;
import com.aisino.inveli.vinda.utils.AlertUtil;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Window;




/**
 * @author leifeng
 * @Date 2017-11-22
 **/
@FXMLController
public class AddCustomerController{

    @FXML
    private TextField regNumber;

    @FXML
    private TextField bank;

    @FXML
    private TextField cusName;

    @FXML
    private TextField email;

    @FXML
    private TextField addAndTel;

    private CustomerService customerService;

    @FXML
    void addAction(ActionEvent event) {
        Window window = ((Button) event.getSource()).getScene().getWindow();
        if ("".equals(cusName.getText())||cusName.getText()==null){
            AlertUtil.showErrAlert("", window,"客户名称不能为空");
            return;
        }
        Customer customer = new Customer();
        customer.setCusName(cusName.getText());
        customer.setAddAndTel(addAndTel.getText());
        customer.setRegNumber(regNumber.getText());
        customer.setBank(bank.getText());
        customer.setEmail(email.getText());
        customerService.save(customer);
        AlertUtil.confirmAlert("添加成功",window,"");
        window.hide();
    }

    @FXML
    void exitAction(ActionEvent event) {
        Window window = ((Button) event.getSource()).getScene().getWindow();
        window.hide();
    }

    /**
     * 初始化service
     * @param customerService
     */
    public void initData(CustomerService customerService) {
        this.customerService = customerService;
    }

}
